#define _CRT_SECURE_NO_WARNINGS



#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int sort_nums(int num)
{
    int sum = 0;
    while (num)
    {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}
bool cmp(int a, int b)
{
    if (sort_nums(a) != sort_nums(b))
        return sort_nums(a) < sort_nums(b);
    else
        return a < b;
}
int main()
{
    int n, m;
    vector<int> nums;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        nums.push_back(i);
    sort(nums.begin(), nums.end(), cmp);
    cout << nums[m - 1];
    return 0;
}
